def word_to_digit(word):
    words = {
        "zero": "0",
        "one": "1",
        "two": "2",
        "three": "3",
        "four": "4",
        "five": "5",
        "six": "6",
        "seven": "7",
        "eight": "8",
        "nine": "9"
    }
    return words.get(word)

def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

e = input().split()
if len(e) != 3:
    print("Wrong input")
else:
    g_str = "".join([word_to_digit(word) for word in e])
    if not g_str.isdigit() or len(g_str) != 3:
        print("Wrong input")
    else:
        g = int(g_str)
        a = None
        c = None
        i = 1
        while True:
            if g - i >= 0 and is_prime(g - i):
                a = g - i
                break
            if is_prime(g + i):
                c = g + i
                break
            i += 1
        
        if a is not None:
            print(a)
        if c is not None:
            print(c)

